package com.szh.zuoye;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {


    private static final String TAG = "MyReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        MyDBHelper helper=new MyDBHelper(context);
        SQLiteDatabase db=helper.getReadableDatabase();
        String action = intent.getAction();
        if ("com.szh.zuoye".equals(action)) {
            String name = intent.getStringExtra("name");
            String pwd = intent.getStringExtra("pwd");
            Log.d(TAG, "name: "+name);
            Log.d(TAG, "pwd: "+pwd);
            Cursor user = db.query("user", null, "username=?", new String[]{name}, null, null, null);
            user.moveToNext();
            String userPwd = user.getString(user.getColumnIndex("userPwd"));
            if (pwd.equals(userPwd)) {
                Toast.makeText(context, "登录成功", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context, "登录失败", Toast.LENGTH_SHORT).show();
            }
        }
    }

}
